import java.util.ArrayList;
import java.util.List;

class BaseConverter {

    private final int baseNumber;
    private final int[] ints;

    BaseConverter(int baseNumber, int[] ints) {
        if (baseNumber < 2) {
            throw new IllegalArgumentException("Bases must be at least 2.");
        }

        if (ints.length <= 0) {
            throw new IllegalArgumentException("You must supply at least one digit.");
        }

        if (ints.length > 1 && ints[0] == 0) {
            throw new IllegalArgumentException("Digits may not contain leading zeros.");
        }

        for (int anInt : ints)
            if (anInt < 0) {
                throw new IllegalArgumentException("Digits may not be negative.");
            }

        for (int anInt : ints)
            if (anInt >= baseNumber) {
                throw new IllegalArgumentException("All digits must be strictly less than the base.");
            }

        this.baseNumber = baseNumber;
        this.ints = ints;
    }

    int[] convertToBase(int i) {

        if (i < 2) throw new IllegalArgumentException("Bases must be at least 2.");

        int length = this.ints.length - 1;
        int number = 0;
        for (int j = 0; j < this.ints.length; j++) {
            number += this.ints[j] * Math.pow((double) this.baseNumber, length - j);
        }

        List<Integer> li = new ArrayList<>();
        while (number >= i) {
            li.add(0, number % i);
            number = number / i;
        }
        li.add(0, number);

        int[] results = new int[li.size()];
        for (int j = 0; j < li.size(); j++) {
            results[j] = li.get(j);
        }
        return results;
    }
}